package com.dkd.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.system.domain.TCodeRule;
import com.dkd.system.service.ITCodeRuleService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 系统编码规则Controller
 * 
 * @author chuyongshuo
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/security/encoder")
public class TCodeRuleController extends BaseController
{
    @Autowired
    private ITCodeRuleService tCodeRuleService;

    /**
     * 查询系统编码规则列表
     */
    @PreAuthorize("@ss.hasPermi('security:encoder:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCodeRule tCodeRule)
    {
        startPage();
        List<TCodeRule> list = tCodeRuleService.selectTCodeRuleList(tCodeRule);
        System.out.println("list = " + list);
        return getDataTable(list);
    }

    /**
     * 导出系统编码规则列表
     */
    @PreAuthorize("@ss.hasPermi('security:encoder:export')")
    @Log(title = "系统编码规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCodeRule tCodeRule)
    {
        List<TCodeRule> list = tCodeRuleService.selectTCodeRuleList(tCodeRule);
        ExcelUtil<TCodeRule> util = new ExcelUtil<TCodeRule>(TCodeRule.class);
        util.exportExcel(response, list, "系统编码规则数据");
    }

    /**
     * 获取系统编码规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('security:encoder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tCodeRuleService.selectTCodeRuleById(id));
    }

    /**
     * 新增系统编码规则
     */
    @PreAuthorize("@ss.hasPermi('security:encoder:add')")
    @Log(title = "系统编码规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCodeRule tCodeRule)
    {
        return toAjax(tCodeRuleService.insertTCodeRule(tCodeRule));
    }

    /**
     * 修改系统编码规则
     */
    @PreAuthorize("@ss.hasPermi('security:encoder:edit')")
    @Log(title = "系统编码规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCodeRule tCodeRule)
    {
        return toAjax(tCodeRuleService.updateTCodeRule(tCodeRule));
    }

    /**
     * 删除系统编码规则
     */
    @PreAuthorize("@ss.hasPermi('security:encoder:remove')")
    @Log(title = "系统编码规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tCodeRuleService.deleteTCodeRuleByIds(ids));
    }
}
